// packageA/pages/package/kanban/kanban.js
import * as echarts from "../../../components/echarts/echarts";
const mybehavior = require("../../../../behaviors/requests")
var company = ""
var chart;
var chart1;
var chart2;
var chart3;
var get_obj_length = function (t_data) {
  let max_size = 0;
  for (let key in t_data) {
    let values = t_data[key];
    for (let index in values) {
      if (index > max_size) {
        max_size = index;
      }
    }
  }
  return max_size;
}
function drawChart(canvas, width, height, dpr) {
  chart = echarts.init(canvas, null, {
    width: width,
    height: height,
    devicePixelRatio: dpr
  });
  canvas.setChart(chart);
  let url = "https://logisticsengineering.gree.com/package_integrated_api/analysis_manage/hours_outdoor_analysis"
  let data = {
    company: company
  }
  var token = wx.getStorageSync('token')
  wx.request({
    url: url,
    method: "post",
    data: data,
    header: {
      "Authorization": token
    },
    success(res) {
      let result = res.data
      let today_arr = Object.values(result.data[0])
      let onedaybefore_arr = Object.values(result.data[1])
      let sevendaybefore_arr = Object.values(result.data[2])
      // console.log("today_arr",today_arr);
      // console.log("onedaybefore_arr",onedaybefore_arr);
      // console.log("sevendaybefore_arr",sevendaybefore_arr);

      let option = {
        color: ['#1890FF', '#52E3A9'], //'#FFB566',
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            crossStyle: {
              color: '#999'
            }
          }
        },
        splitLine: {
          color: '#85C2FC'
        },

        xAxis: [{
          boundaryGap: false, //过长隐藏x轴文字
          splitLine: {
            show: false,
            lineStyle: {
              color: ['rgba(133, 194, 252, 0.4)'],
              width: 1,
              type: 'solid'
            }
          },
          axisLine: {
            lineStyle: {
              type: 'solid',
              // color: 'rgba(133, 194, 252, 0.4)', //坐标线的颜色
              color: '#DBD8D9',
              width: '1' //坐标线的宽度
            }
          },
          axisLabel: {

            //x轴文字的配置
            show: true,
            textStyle: {
              interval: 0,
              color: '#808080',
              fontSize: '10px',
            }
          },
          type: 'category',
          data: [
            '00:00',
            '01:00',
            '02:00',
            '03:00',
            '04:00',
            '05:00',
            '06:00',
            '07:00',
            '08:00',
            '09:00',
            '10:00',
            '11:00',
            '12:00',
            '13:00',
            '14:00',
            '15:00',
            '16:00',
            '17:00',
            '18:00',
            '19:00',
            '20:00',
            '21:00',
            '22:00',
            '23:00',
          ],
          axisPointer: {
            type: 'shadow'
          }
        }],
        yAxis: [
          {
            type: 'value',
            name: '',
            min: 0,
            max: 20,
            interval: 5,
            axisLabel: {
              //y轴文字的配置
              formatter: '{value}',
              show: true,
              textStyle: {

                color: '#808080',
                fontSize: '10px'
              },
              // formatter: '{value} %'//y轴的每一个刻度值后面加上‘%’号
            },

            axisLine: {
              lineStyle: {
                type: 'solid',
                color: 'rgba(133, 194, 252, 0.4)', //坐标线的颜色
                width: '2' //坐标线的宽度
              }
            },
            splitLine: {
              show: true,
              lineStyle: {
                // color: ['rgba(133, 194, 252, 0.4)'],
                color: '#DBD8D9',
                width: 1,
                type: 'solid'
              }
            },
          },
          {
            type: 'value',
            name: '',
            show: false,
            min: 0,
            max: 20,
            interval: 5,
            axisLabel: {
              formatter: '{value}'
            }
          }
        ],
        series: [
          {
            name: 'Evaporation',
            type: 'line',
            smooth: true, //平滑
            showSymbol: false,
            lineStyle: {
              // 阴影部分
              width: 1, // 线条颜色、粗细
              color: '#88ffac',
              shadowOffsetX: 0, // 折线的X偏移
              shadowOffsetY: 4, // 折线的Y偏移
              shadowBlur: 8, // 折线模糊
              shadowColor: 'rgba(255, 181, 102, 0.4)' //折线颜色
            },
            color: '#FFB566',
            yAxisIndex: 1,
            tooltip: {
              valueFormatter: function (value) {
                return value + ' °C';
              }
            },

            data: today_arr
          },
          {
            name: 'Precipitation',
            type: 'line',
            smooth: true, //平滑
            lineStyle: {
              // 阴影部分
              width: 1, // 线条颜色、粗细
              color: '#555fff',
              shadowOffsetX: 0, // 折线的X偏移
              shadowOffsetY: 4, // 折线的Y偏移
              shadowBlur: 8, // 折线模糊
              shadowColor: 'rgba(3,116,255,0.4)' //折线颜色
            },
            showSymbol: false,

            color: '#555fff',
            yAxisIndex: 1,
            tooltip: {
              valueFormatter: function (value) {
                return value + ' °C';
              }
            },
            data: onedaybefore_arr
          },
          {
            name: '22',
            type: 'line',
            showSymbol: false,
            lineStyle: {
              // 阴影部分
              width: 1, // 线条颜色、粗细
              color: '#ecb500',
              shadowOffsetX: 0, // 折线的X偏移
              shadowOffsetY: 4, // 折线的Y偏移
              shadowBlur: 8, // 折线模糊
              shadowColor: 'rgba(3,116,255,0.4);' //折线颜色
            },
            smooth: true,
            color: '#fff788',
            yAxisIndex: 1,
            tooltip: {
              valueFormatter: function (value) {
                return value + ' °C';
              }
            },
            data: sevendaybefore_arr
          }
        ]
      };
      chart.setOption(option);
    }
  });



}
function drawChart1(canvas, width, height, dpr) {
  chart1 = echarts.init(canvas, null, {
    width: width,
    height: height,
    devicePixelRatio: dpr
  });
  canvas.setChart(chart1);
  let url = "https://logisticsengineering.gree.com/package_integrated_api/analysis_manage/sign_time_summary"
  let data = {
    company: company,
  }
  var token = wx.getStorageSync('token')
  wx.request({
    url: url,
    method: "post",
    data: data,
    header: {
      "Authorization": token
    },
    success(res) {
      let result = res.data
      let yAxis_arr = Object.keys(result.data)
      let series_arr = []
      let color_list = ['#555fff', '#AAFFF3', '#ecb500', '#b36cd4', '#bd3653', '#77bd36']
      let max_size = 5
      let index = 1;
      let result_arr = {};
      let title_arr = []
      while (index <= max_size) {
        title_arr.push('第' + index + '环节')
        result_arr[index] || (result_arr[index] = []);
        for (let key in result.data) {
          let vs = result.data[key];
          let new_value = (vs[index] / 60) | 0 || (new_value = 0);
          result_arr[index].push(new_value);
        }
        index += 1;
      };

      for (let i = 0; i < title_arr.length; i++) {
        let obj = {
          name: title_arr[i],
          type: 'bar',
          barWidth: '40%',
          stack: 'total',
          itemStyle: {
            // 设置柱状图的颜色
            color: color_list[i]
          },
          // label: {
          //   show: true
          // },
          emphasis: {
            focus: 'series'
          },
          data: result_arr[i + 1]
        }
        series_arr.push(obj)
      }
      let option1 = {
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            // Use axis to trigger tooltip
            type: 'shadow' // 'shadow' as default; can also be 'line' or 'shadow'
          }
        },

        legend: {
          top: '20%',
        },
        grid: {
          left: '0%',
          bottom: '10%',
          top: '40%',
          containLabel: true
        },
        xAxis: {
          type: 'value',

        },
        yAxis: {
          type: 'category',
          data: yAxis_arr,

        },
        series: series_arr
      };
      // console.log("drawChart1", option1);

      chart1.setOption(option1);
    }
  });
}
function drawChart2(canvas, width, height, dpr) {
  chart2 = echarts.init(canvas, null, {
    width: width,
    height: height,
    devicePixelRatio: dpr
  });
  canvas.setChart(chart2);

  let url = "https://logisticsengineering.gree.com/package_integrated_api/analysis_manage/days_outdoor_analysis"
  let data = {
    company: company,
  }
  var token = wx.getStorageSync('token')
  wx.request({
    url: url,
    method: "post",
    data: data,
    header: {
      "Authorization": token
    },
    success(res) {
      let result = res.data
      let res_arr = Array.from(Object.values(result.data))
      let xAxis_arr = []
      let series_list = []
      for (let i = 0; i < res_arr.length; i++) {
        xAxis_arr.push(Object.keys(res_arr[i])[0].slice(5, 10))
        series_list.push(Object.values(res_arr[i])[0])
      }
      xAxis_arr = xAxis_arr.slice().reverse()
      series_list = series_list.slice().reverse()
      var option2 = {
        xAxis: {
          type: 'category',
          axisLabel: { interval: 0, rotate: 30 },
          data: xAxis_arr
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            data: series_list,
            type: 'bar',
            barWidth: '30%',
            label: {
              show: true, // 显示数值
              position: 'top' // 数值显示的位置
            },
            itemStyle: {
              color: function (params) {
                // params是一个包含数据相关信息的对象
                var colorList = ['#555fff', '#AAFFF3', '#555fff', '#AAFFF3', '#555fff', '#AAFFF3', '#555fff', '#AAFFF3',];
                return colorList[params.dataIndex];
              }
            },
          }

        ]
      };
      chart2.setOption(option2);
    }
  });



}
function drawChart3(canvas, width, height, dpr) {
  chart3 = echarts.init(canvas, null, {
    width: width,
    height: height,
    devicePixelRatio: dpr
  });
  canvas.setChart(chart3);

  let url = "https://logisticsengineering.gree.com/package_integrated_api/analysis_manage/outdoor_result"
  let data = {
    company: company,
  }
  var token = wx.getStorageSync('token')
  wx.request({
    url: url,
    method: "post",
    data: data,
    header: {
      "Authorization": token
    },
    success(res) {
      let result = res.data.data
      let lists = [
        {
          value: result.agree, name: '合规放行'
        },
        {
          value: result.disagree, name: '违规禁出'
        },
      ]

      var option3 = {
        toolbox: {
          show: true,
        },
        tooltip: {
          trigger: 'item',
          formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        legend: {
          top: '70%',
          left: 'left',

        },

        series: [
          {

            name: 'Access From',
            type: 'pie',
            radius: '50%',
            center: ['50%', "35%"],
            avoidLabelOverlap: false,
            itemStyle: {
              borderRadius: 10,
              borderColor: '#fff',
              borderWidth: 2
            },
            label: {
              show: false,
              position: 'center'
            },
            emphasis: {
              label: {
                show: true,
                fontSize: 30,
                fontWeight: 'bold'
              }
            },
            labelLine: {
              show: false
            },
            data: lists,
            itemStyle: {
              normal: {
                color: function (params) {
                  // 预定义一个颜色数组
                  var colorList = [
                    '#5555FF', '#AAFFF3'
                  ];
                  // 返回每个饼图扇区的颜色
                  return colorList[params.dataIndex % colorList.length];
                },
                label: {
                  show: true,
                  formatter: ' {c} ({d}%)'
                },
                labelLine: { show: true }
              }
            }


          }
        ]
      };
      chart3.setOption(option3);
    }
  });






}
Page({

  /**
   * 页面的初始数据
   */
  behaviors: [mybehavior],
  data: {
    baseUrl: "https://logisticsengineering.gree.com/package_integrated_api/analysis_manage",
    company: "",
    ec: {
      onInit: drawChart
    },
    ec1: {
      onInit: drawChart1
    },
    ec2: {
      onInit: drawChart2
    },
    ec3: {
      onInit: drawChart3
    },
    user_data_obj: {},
    hours_outdoor: ['a', 'b'],
    now_day: "",
    last_month_day: "",
    now: "",
    factory_options: [],
    factory_options1: [],
    company: "",
    popup_show: false,
    search_value: "",
    ec1_haidden: false,
    today_arr: [],
    onedaybefore_arr: [],
    sevendaybefore_arr: [],

  },
  // 切换公司按钮
  navChange() {
    this.setData({
      ec1_haidden: true,
      popup_show: true,
    })
  },
  // 公司搜索框
  onSearch(e) {
    if (e.detail == "") {
      let arr = this.data.factory_options1
      this.setData({
        factory_options: arr
      })
    } else {

      let list1 = this.data.factory_options1
      let arr = []
      for (let i = 0; i < list1.length; i++) {
        if (list1[i].match(this.data.search_value) != null) {
          arr.push(list1[i]);
        }
      }
      this.setData({
        factory_options: arr
      })

    }
  },
  // 确认公司名称
  onPopupChange(e) {
    this.setData({
      company: e.detail.value,
      popup_show: false,
      hours_outdoor: ['a', 'b']
    })
    wx.showLoading({
      title: '加载中...',
    })
    this.getUserDatas()
    this.getHoursDatas()
    this.getHoursDatas1()
    this.getSignDatas()
    this.getDaysDatas()
    this.getOutdoorDatas()
    setTimeout(() => {
      this.setData({
        ec1_haidden: false
      })
      wx.hideLoading()
    }, 500)
  },
  // 关闭公司切换弹窗
  onClose() {
    this.setData({
      popup_show: false,
      ec1_haidden: false,

    })
  },
  // 获取公司名称
  getFactoryDate() {
    var url = "https://logisticsengineering.gree.com/package_integrated_api/data_auth_manage/get_u_permission";
    var data = {}

    this.post(url, data).then(res => {
      // console.log("返回回收类别结果", res)
      if (res.code == 20000) {
        let factory_name_list = []
        for (let i in res.data) {
          if (res.data.hasOwnProperty(i))
            factory_name_list.push(i)
        }
        let filteredArray = factory_name_list.filter(item => item !== "供应商" && item !== "物流人员"&& item !== "第三方物流");
        this.setData({
          factory_options: filteredArray,
          factory_options1: filteredArray,
        })

        // wx.showToast({
        //   title: res.msg,
        //   icon: "success"
        // });
      } else {
        // wx.showToast({
        //   title: res.msg,
        //   icon: "error"
        // })
      }
    }).catch(err => {
      // wx.showToast({
      //   title: err.msg,
      //   icon: 'error'
      // })
    })
  },
  // 获取--用户数量分析--数据
  getUserDatas() {
    let url = this.data.baseUrl + "/users_analysis"
    let data = {
      company: ""
    }
    this.post(url, data).then(res => {
      // console.log("用户数量分析", res)
      if (res.code == 20000) {
        this.setData({
          user_data_obj: res.data
        })

      } else {
       
        // wx.showToast({
        //   title: res.msg,
        //   icon: 'error'
        // })
      }
    }).catch(err => {
  
      console.log(err);
      // wx.showToast({
      //   title: err.msg,
      //   icon: 'error'
      // })
    })
  },
  // 选择出门实时数据
  onCheckboxChange(event) {
    // console.log(event);
    this.setData({
      hours_outdoor: event.detail,
    });
    if (JSON.stringify(this.data.hours_outdoor) === JSON.stringify(["a"])) {
      this.selectHoursDatas(this.data.today_arr, this.data.onedaybefore_arr, [])
    } else if (JSON.stringify(this.data.hours_outdoor) == JSON.stringify(['b'])) {
      this.selectHoursDatas(this.data.today_arr, [], this.data.sevendaybefore_arr)
    } else if (JSON.stringify(this.data.hours_outdoor) == JSON.stringify(['a', 'b'])) {
      this.selectHoursDatas(this.data.today_arr, this.data.onedaybefore_arr, this.data.sevendaybefore_arr)
    } else if (JSON.stringify(this.data.hours_outdoor) == JSON.stringify(['b', 'a'])) {
      this.selectHoursDatas(this.data.today_arr, this.data.onedaybefore_arr, this.data.sevendaybefore_arr)
    }
    else {
      this.selectHoursDatas(this.data.today_arr, [], [])
    }
  },
  selectHoursDatas(today, onedaybefore, sevendaybefore) {

    let today_arr = today
    let onedaybefore_arr = onedaybefore
    let sevendaybefore_arr = sevendaybefore
    let option = {
      color: ['#1890FF', '#52E3A9'], //'#FFB566',
      tooltip: {
        trigger: 'axis',
        axisPointer: {
          type: 'cross',
          crossStyle: {
            color: '#999'
          }
        }
      },
      splitLine: {
        color: '#85C2FC'
      },

      xAxis: [{
        boundaryGap: false, //过长隐藏x轴文字
        splitLine: {
          show: false,
          lineStyle: {
            color: ['rgba(133, 194, 252, 0.4)'],
            width: 1,
            type: 'solid'
          }
        },
        axisLine: {
          lineStyle: {
            type: 'solid',
            // color: 'rgba(133, 194, 252, 0.4)', //坐标线的颜色
            color: '#DBD8D9',
            width: '1' //坐标线的宽度
          }
        },
        axisLabel: {

          //x轴文字的配置
          show: true,
          textStyle: {
            interval: 0,
            color: '#808080',
            fontSize: '10px',
          }
        },
        type: 'category',
        data: [
          '00:00',
          '01:00',
          '02:00',
          '03:00',
          '04:00',
          '05:00',
          '06:00',
          '07:00',
          '08:00',
          '09:00',
          '10:00',
          '11:00',
          '12:00',
          '13:00',
          '14:00',
          '15:00',
          '16:00',
          '17:00',
          '18:00',
          '19:00',
          '20:00',
          '21:00',
          '22:00',
          '23:00',
        ],
        axisPointer: {
          type: 'shadow'
        }
      }],
      yAxis: [
        {
          type: 'value',
          name: '',
          min: 0,
          max: 20,
          interval: 5,
          axisLabel: {
            //y轴文字的配置
            formatter: '{value}',
            show: true,
            textStyle: {

              color: '#808080',
              fontSize: '10px'
            }
            // formatter: '{value} %'//y轴的每一个刻度值后面加上‘%’号
          },

          axisLine: {
            lineStyle: {
              type: 'solid',
              color: 'rgba(133, 194, 252, 0.4)', //坐标线的颜色
              width: '2' //坐标线的宽度
            }
          },
          splitLine: {
            show: true,
            lineStyle: {
              // color: ['rgba(133, 194, 252, 0.4)'],
              color: '#DBD8D9',
              width: 1,
              type: 'solid'
            }
          },
        },
        {
          type: 'value',
          name: '',
          show: false,
          min: 0,
          max: 20,
          interval: 5,
          axisLabel: {
            formatter: '{value}'
          }
        }
      ],
      series: [
        {
          name: 'Evaporation',
          type: 'line',
          smooth: true, //平滑
          showSymbol: false,
          lineStyle: {
            // 阴影部分
            width: 1, // 线条颜色、粗细
            color: '#88ffac',
            shadowOffsetX: 0, // 折线的X偏移
            shadowOffsetY: 4, // 折线的Y偏移
            shadowBlur: 8, // 折线模糊
            shadowColor: 'rgba(255, 181, 102, 0.4)' //折线颜色
          },
          color: '#FFB566',
          yAxisIndex: 1,
          tooltip: {
            valueFormatter: function (value) {
              return value + ' °C';
            }
          },

          data: today_arr
        },
        {
          name: 'Precipitation',
          type: 'line',
          smooth: true, //平滑
          lineStyle: {
            // 阴影部分
            width: 1, // 线条颜色、粗细
            color: '#555fff',
            shadowOffsetX: 0, // 折线的X偏移
            shadowOffsetY: 4, // 折线的Y偏移
            shadowBlur: 8, // 折线模糊
            shadowColor: 'rgba(3,116,255,0.4)' //折线颜色
          },
          showSymbol: false,

          color: '#555fff',
          yAxisIndex: 1,
          tooltip: {
            valueFormatter: function (value) {
              return value + ' °C';
            }
          },
          data: onedaybefore_arr
        },
        {
          name: '22',
          type: 'line',
          showSymbol: false,
          lineStyle: {
            // 阴影部分
            width: 1, // 线条颜色、粗细
            color: '#ecb500',
            shadowOffsetX: 0, // 折线的X偏移
            shadowOffsetY: 4, // 折线的Y偏移
            shadowBlur: 8, // 折线模糊
            shadowColor: 'rgba(3,116,255,0.4);' //折线颜色
          },
          smooth: true,
          color: '#fff788',
          yAxisIndex: 1,
          tooltip: {
            valueFormatter: function (value) {
              return value + ' °C';
            }
          },
          data: sevendaybefore_arr
        }
      ]
    };
    chart.setOption(option);
  },
  // 获取--出门实时数据分析--数据
  getHoursDatas1() {
    let url = this.data.baseUrl + "/hours_outdoor_analysis"
    let data = {
      company: this.data.company
    }
    this.post(url, data).then(res => {
      // console.log("出门实时数据分析", res)

      if (res.code == 20000) {

        this.setData({
          today_arr: Object.values(res.data[0]),
          onedaybefore_arr: Object.values(res.data[1]),
          sevendaybefore_arr: Object.values(res.data[2])
        })


      } else {
        // wx.showToast({
        //   title: res.msg,
        //   icon: 'error'
        // })
      }
    }).catch(err => {
      console.log(err);
      // wx.showToast({
      //   title: err.msg,
      //   icon: 'error'
      // })
    })
  },
  // 获取--出门实时数据分析--数据
  getHoursDatas() {
    let url = this.data.baseUrl + "/hours_outdoor_analysis"
    let data = {
      company: this.data.company
    }
    this.post(url, data).then(res => {
      // console.log("出门实时数据分析", res)

      if (res.code == 20000) {
        let today_arr = Object.values(res.data[0])
        let onedaybefore_arr = Object.values(res.data[1])
        let sevendaybefore_arr = Object.values(res.data[2])
        let option = {
          color: ['#1890FF', '#52E3A9'], //'#FFB566',
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              type: 'cross',
              crossStyle: {
                color: '#999'
              }
            }
          },
          splitLine: {
            color: '#85C2FC'
          },

          xAxis: [{
            boundaryGap: false, //过长隐藏x轴文字
            splitLine: {
              show: false,
              lineStyle: {
                color: ['rgba(133, 194, 252, 0.4)'],
                width: 1,
                type: 'solid'
              }
            },
            axisLine: {
              lineStyle: {
                type: 'solid',
                // color: 'rgba(133, 194, 252, 0.4)', //坐标线的颜色
                color: '#DBD8D9',
                width: '1' //坐标线的宽度
              }
            },
            axisLabel: {

              //x轴文字的配置
              show: true,
              textStyle: {
                interval: 0,
                color: '#808080',
                fontSize: '10px',
              }
            },
            type: 'category',
            data: [
              '00:00',
              '01:00',
              '02:00',
              '03:00',
              '04:00',
              '05:00',
              '06:00',
              '07:00',
              '08:00',
              '09:00',
              '10:00',
              '11:00',
              '12:00',
              '13:00',
              '14:00',
              '15:00',
              '16:00',
              '17:00',
              '18:00',
              '19:00',
              '20:00',
              '21:00',
              '22:00',
              '23:00',
            ],
            axisPointer: {
              type: 'shadow'
            }
          }],
          yAxis: [
            {
              type: 'value',
              name: '',
              min: 0,
              max: 20,
              interval: 5,
              axisLabel: {
                //y轴文字的配置
                formatter: '{value}',
                show: true,
                textStyle: {

                  color: '#808080',
                  fontSize: '10px'
                }
                // formatter: '{value} %'//y轴的每一个刻度值后面加上‘%’号
              },

              axisLine: {
                lineStyle: {
                  type: 'solid',
                  color: 'rgba(133, 194, 252, 0.4)', //坐标线的颜色
                  width: '2' //坐标线的宽度
                }
              },
              splitLine: {
                show: true,
                lineStyle: {
                  // color: ['rgba(133, 194, 252, 0.4)'],
                  color: '#DBD8D9',
                  width: 1,
                  type: 'solid'
                }
              },
            },
            {
              type: 'value',
              name: '',
              show: false,
              min: 0,
              max: 20,
              interval: 5,
              axisLabel: {
                formatter: '{value}'
              }
            }
          ],
          series: [
            {
              name: 'Evaporation',
              type: 'line',
              smooth: true, //平滑
              showSymbol: false,
              lineStyle: {
                // 阴影部分
                width: 1, // 线条颜色、粗细
                color: '#88ffac',
                shadowOffsetX: 0, // 折线的X偏移
                shadowOffsetY: 4, // 折线的Y偏移
                shadowBlur: 8, // 折线模糊
                shadowColor: 'rgba(255, 181, 102, 0.4)' //折线颜色
              },
              color: '#FFB566',
              yAxisIndex: 1,
              tooltip: {
                valueFormatter: function (value) {
                  return value + ' °C';
                }
              },

              data: today_arr
            },
            {
              name: 'Precipitation',
              type: 'line',
              smooth: true, //平滑
              lineStyle: {
                // 阴影部分
                width: 1, // 线条颜色、粗细
                color: '#555fff',
                shadowOffsetX: 0, // 折线的X偏移
                shadowOffsetY: 4, // 折线的Y偏移
                shadowBlur: 8, // 折线模糊
                shadowColor: 'rgba(3,116,255,0.4)' //折线颜色
              },
              showSymbol: false,

              color: '#555fff',
              yAxisIndex: 1,
              tooltip: {
                valueFormatter: function (value) {
                  return value + ' °C';
                }
              },
              data: onedaybefore_arr
            },
            {
              name: '22',
              type: 'line',
              showSymbol: false,
              lineStyle: {
                // 阴影部分
                width: 1, // 线条颜色、粗细
                color: '#ecb500',
                shadowOffsetX: 0, // 折线的X偏移
                shadowOffsetY: 4, // 折线的Y偏移
                shadowBlur: 8, // 折线模糊
                shadowColor: 'rgba(3,116,255,0.4);' //折线颜色
              },
              smooth: true,
              color: '#fff788',
              yAxisIndex: 1,
              tooltip: {
                valueFormatter: function (value) {
                  return value + ' °C';
                }
              },
              data: sevendaybefore_arr
            }
          ]
        };
        chart.setOption(option);


      } else {
        // wx.showToast({
        //   title: res.msg,
        //   icon: 'error'
        // })
      }
    }).catch(err => {
      console.log(err);
      // wx.showToast({
      //   title: err.msg,
      //   icon: 'error'
      // })
    })
  },
  // 获取--系统出门签审平均完成时间分析--数据
  getSignDatas() {
    let url = this.data.baseUrl + "/sign_time_summary"
    let data = {
      company: this.data.company
    }
    this.post(url, data).then(res => {
      // console.log("系统出门签审平均完成时间分析", res)
      if (res.code == 20000) {

        let yAxis_arr = Object.keys(res.data)
        let series_arr = []
        let color_list = ['#555fff', '#AAFFF3', '#ecb500', '#b36cd4', '#bd3653', '#77bd36'];
        let max_size = 5;
        let index = 1;
        let result_arr = {};
        let title_arr = []
        while (index <= max_size) {
          title_arr.push('第' + index + '环节')
          result_arr[index] || (result_arr[index] = []);
          for (let key in res.data) {
            let vs = res.data[key];
            let new_value = vs[index]/60 || (new_value = 0);
            result_arr[index].push(new_value);
          }
          index += 1;
        };
        // console.log("max_size", max_size);
        // console.log("result_arr", result_arr);
        // console.log("title_arr", title_arr);
        // console.log("yAxis_arr", yAxis_arr);

        for (let i = 0; i < title_arr.length; i++) {
          let obj = {
            name: title_arr[i],
            type: 'bar',
            barWidth: '40%',
            stack: 'total',
            itemStyle: {
              // 设置柱状图的颜色
              color: color_list[i]
            },
            // label: {
            //   show: true
            // },
            emphasis: {
              focus: 'series'
            },
            data: result_arr[i + 1]
          }
     
          series_arr.push(obj)
        }
        // console.log("series_arr", series_arr);
        let option1 = {
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              // Use axis to trigger tooltip
              type: 'shadow' // 'shadow' as default; can also be 'line' or 'shadow'
            }
          },
          legend: {},
          grid: {
            left: '0%',
            bottom: '10%',
            top: '40%',
            containLabel: true
          },
          xAxis: {
            type: 'value'
          },
          yAxis: {
            type: 'category',
            data: yAxis_arr
          },
          series: series_arr
        };
        chart1.setOption(option1);

      } else {
        // wx.showToast({
        //   title: res.msg,
        //   icon: 'error'
        // })
      }
    }).catch(err => {
      console.log(err);
      // wx.showToast({
      //   title: err.msg,
      //   icon: 'error'
      // })
    })
  },
  // 获取--每天使用系统单据出门车次分析--数据
  getDaysDatas() {
    let url = this.data.baseUrl + "/days_outdoor_analysis"
    let data = {
      company: this.data.company
    }
    this.post(url, data).then(res => {
      // console.log("每天使用系统单据出门车次分析", res)

      if (res.code == 20000) {
        let res_arr = Array.from(Object.values(res.data))
        let xAxis_arr = []
        let series_list = []
        for (let i = 0; i < res_arr.length; i++) {
          xAxis_arr.push(Object.keys(res_arr[i])[0].slice(5, 10))
          series_list.push(Object.values(res_arr[i])[0])
        }
        xAxis_arr = xAxis_arr.slice().reverse()
        series_list = series_list.slice().reverse()
        var option2 = {
          xAxis: {
            type: 'category',
            axisLabel: { interval: 0, rotate: 30 },
            data: xAxis_arr
          },
          yAxis: {
            type: 'value'
          },
          series: [
            {
              data: series_list,
              type: 'bar',
              barWidth: '30%',
              label: {
                show: true, // 显示数值
                position: 'top' // 数值显示的位置
              },
              itemStyle: {
                color: function (params) {
                  // params是一个包含数据相关信息的对象
                  var colorList = ['#555fff', '#AAFFF3', '#555fff', '#AAFFF3', '#555fff', '#AAFFF3', '#555fff', '#AAFFF3',];
                  return colorList[params.dataIndex];
                }
              },
            }

          ]
        };
        chart2.setOption(option2);

      } else {
        // wx.showToast({
        //   title: res.msg,
        //   icon: 'error'
        // })
      }
    }).catch(err => {
      console.log(err);
      // wx.showToast({
      //   title: err.msg,
      //   icon: 'error'
      // })
    })
  },
  // 获取--出门查验结果分析--数据
  getOutdoorDatas() {
    let url = this.data.baseUrl + "/outdoor_result"
    let data = {
      company: this.data.company
    }
    this.post(url, data).then(res => {
      // console.log("出门查验结果分析", res)

      if (res.code == 20000) {
        let lists = [
          {
            value: res.data.agree, name: '合规放行'
          },
          {
            value: res.data.disagree, name: '违规禁出'
          },
        ]

        var option3 = {
          toolbox: {
            show: true,
          },
          tooltip: {
            trigger: 'item',
            formatter: "{a} <br/>{b} : {c} ({d}%)"
          },
          legend: {
            top: '70%',
            left: 'left',

          },

          series: [
            {

              name: 'Access From',
              type: 'pie',
              radius: '50%',
              center: ['50%', "35%"],
              avoidLabelOverlap: false,
              itemStyle: {
                borderRadius: 10,
                borderColor: '#fff',
                borderWidth: 2
              },
              label: {
                show: false,
                position: 'center'
              },
              emphasis: {
                label: {
                  show: true,
                  fontSize: 30,
                  fontWeight: 'bold'
                }
              },
              labelLine: {
                show: false
              },
              data: lists,
              itemStyle: {
                normal: {
                  color: function (params) {
                    // 预定义一个颜色数组
                    var colorList = [
                      '#5555FF', '#AAFFF3'
                    ];
                    // 返回每个饼图扇区的颜色
                    return colorList[params.dataIndex % colorList.length];
                  },
                  label: {
                    show: true,
                    formatter: ' {c} ({d}%)'
                  },
                  labelLine: { show: true }
                }
              }


            }
          ]
        };
        chart3.setOption(option3);

      } else {
        var option3 = {
          toolbox: {
            show: true,
          },
          tooltip: {
            trigger: 'item',
            formatter: "{a} <br/>{b} : {c} ({d}%)"
          },
          legend: {
            top: '70%',
            left: 'left',
  
          },
  
          series: [
            {
  
              name: 'Access From',
              type: 'pie',
              radius: '50%',
              center: ['50%', "35%"],
              avoidLabelOverlap: false,
              itemStyle: {
                borderRadius: 10,
                borderColor: '#fff',
                borderWidth: 2
              },
              label: {
                show: false,
                position: 'center'
              },
              emphasis: {
                label: {
                  show: true,
                  fontSize: 30,
                  fontWeight: 'bold'
                }
              },
              labelLine: {
                show: false
              },
              data: [
                {
                  value: 0, name: '合规放行'
                },
                {
                  value: 0, name: '违规禁出'
                },
              ],
              itemStyle: {
                normal: {
                  color: function (params) {
                    // 预定义一个颜色数组
                    var colorList = [
                      '#5555FF', '#AAFFF3'
                    ];
                    // 返回每个饼图扇区的颜色
                    return colorList[params.dataIndex % colorList.length];
                  },
                  label: {
                    show: true,
                    formatter: ' {c} ({d}%)'
                  },
                  labelLine: { show: true }
                }
              }
  
  
            }
          ]
        };
        chart3.setOption(option3);
        // wx.showToast({
        //   title: res.msg,
        //   icon: 'error'
        // })
      }
    }).catch(err => {
      var option3 = {
        toolbox: {
          show: true,
        },
        tooltip: {
          trigger: 'item',
          formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        legend: {
          top: '70%',
          left: 'left',

        },

        series: [
          {

            name: 'Access From',
            type: 'pie',
            radius: '50%',
            center: ['50%', "35%"],
            avoidLabelOverlap: false,
            itemStyle: {
              borderRadius: 10,
              borderColor: '#fff',
              borderWidth: 2
            },
            label: {
              show: false,
              position: 'center'
            },
            emphasis: {
              label: {
                show: true,
                fontSize: 30,
                fontWeight: 'bold'
              }
            },
            labelLine: {
              show: false
            },
            data: [
              {
                value: 0, name: '合规放行'
              },
              {
                value: 0, name: '违规禁出'
              },
            ],
            itemStyle: {
              normal: {
                color: function (params) {
                  // 预定义一个颜色数组
                  var colorList = [
                    '#5555FF', '#AAFFF3'
                  ];
                  // 返回每个饼图扇区的颜色
                  return colorList[params.dataIndex % colorList.length];
                },
                label: {
                  show: true,
                  formatter: ' {c} ({d}%)'
                },
                labelLine: { show: true }
              }
            }


          }
        ]
      };
      chart3.setOption(option3);
      console.log(err);
      // wx.showToast({
      //   title: err.msg,
      //   icon: 'error'
      // })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let com = wx.getStorageSync('company')
    company = com
    let now_day = this.gainDate()
    let last_month_day = this.gainBeforeDate()
    let now = this.formatNowTime()
    this.setData({
      company: com,
      now_day: now_day,
      last_month_day: last_month_day,
      now: now
    })
    this.getUserDatas()
    this.getHoursDatas1()
    this.getFactoryDate()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})